package trading.algo.BullTask;

import java.text.DecimalFormat;
import java.util.TimerTask;

import trading.bo.EmailAccessorBO;
import trading.bo.IBAccessorBO;

public class STKShortProtectionOrderTask extends TimerTask {

	private IBAccessorBO ibAccessorBO;
	private EmailAccessorBO emailAccessorBO;
	private String ticker;
	private int size;
	private double trailAmount;
	private double stopPrice;
	
	public STKShortProtectionOrderTask(String ticker, int size, IBAccessorBO ibAccessorBO, EmailAccessorBO emailAccessorBO, double trailAmount, double stopPrice) {
		this.ticker = ticker;
		this.size = size;
		this.ibAccessorBO = ibAccessorBO;
		this.emailAccessorBO = emailAccessorBO;
		DecimalFormat df = new DecimalFormat("#.##");
		this.trailAmount = Double.parseDouble(df.format(trailAmount));
		this.stopPrice = Double.parseDouble(df.format(stopPrice));
	}
	
	@Override
	public void run() {
		this.ibAccessorBO.createTrailStopOrder(ticker, size, trailAmount, stopPrice);
		

        emailAccessorBO.sendStockTrailOrderEmail(ticker, size + "", trailAmount + "");
	}

}
